package com.gao.activitidemo.activititest;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;


/**
 * @author gaofeng
 * @date 2022年09月13日 20:50
 */
public class TaskListenerTest {
    /**
     * 流程部署
     */
    @Test
    public void testActivitiDeployment() {
        // 1.创建ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2. 获取RepositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 3.进行流程部署, 定义一个流程名称, 把bpmn和png部署到数据库中
        Deployment deploy = repositoryService.createDeployment().name("出差申请流程")
                .addClasspathResource("bpmn/evection-listener.bpmn20.xml")
                .addClasspathResource("bpmn/evection-listener.png")
                .deploy();
        // 4.输出部署信息
        System.out.println("流程部署id:" + deploy.getId());
        System.out.println("流程部署id:" + deploy.getName());
    }

    /**
     * 测试监听器,动态设置责任人
     */
    @Test
    public void setAssigneeUel() {
        // 1.创建 ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2.获取RuntimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
        // 3.启动流程实例
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("evection-listener");
        System.out.println("启动成功!" + instance.getName());
    }
}
